﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.IO;
using System.Data.SqlClient;

public partial class OpenQTP : System.Web.UI.Page
{
    SQLInteract objSQL = new SQLInteract();
    protected void Page_Load(object sender, EventArgs e)
    {
        string flow = "";
        try
        {
            flow = objSQL.sqlExecuteScalar("Select Text from Menu where MenuID='" + Session["FlowType"].ToString().Trim() + "'").ToString().Trim();
            ViewState["PageFlow"] = flow;
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "Alert", "<script language=\"javascript\" type=\"text/javascript\" > alert(\"Error:" + ex.Message + "\");</script>", false);
        }
        string ct = flow.Substring(flow.IndexOf('(')+1, flow.IndexOf(')') - (flow.IndexOf('(')+1));
        string ft = flow.Replace(flow.Substring(flow.IndexOf('('), flow.IndexOf(')') - flow.IndexOf('(')), "");
        lbClose.Attributes.Add("onClick", "javascript:window.close();");
        uidbatchname.Text = "<center><font color=red size=4>Execute Batch <br/>" + Request["uidbatch"].Trim().ToString().Remove(Request["uidbatch"].IndexOf("|") + 1, 15) + "</font><center>";
        hdnBatchUsr.Value = Session["UserId"].ToString() + "|" + Request["uidbatch"].Trim().ToString().Substring(Request["uidbatch"].IndexOf("|") + 1, 14).Trim();
        lbDatasheet.Attributes.Add("onclick", "openExcelDocPath('\\\\\\\\20.198.145.93\\\\avivat\\\\FrameworkReconstruction\\\\DataSheet\\\\" + Session["UserID"].ToString() + "\\\\" + Request["uidbatch"].Trim().ToString().Substring(Request["uidbatch"].IndexOf("|") + 1, 14).Trim() + ".xls');return false;");
        //runbatchhyp.Attributes.Add("onclick", "execfile()");
        string fileloc = "file://20.198.145.93/avivat/FrameworkReconstruction/" + ft + "/Driver" + ct + "/Driver" + ct + ".vbs";
        ClientScript.RegisterStartupScript(this.GetType(), "setActiveLI", "document.getElementById(\"runbatchhyp" + "\").setAttribute(\"onclick\", \"CallJS('Demo()','" + fileloc + "');return false;\");", true);
    }
    protected void saveQCbtn_click(object sender, EventArgs e)
    {
        try
        {
            objSQL.sqlExecuteNonQuery("UPDATE [QTP_INPUT] SET [QCUser]='" + txtQCuser.Text.ToString().Trim() + "',[QCPass]='" + txtQCpass.Text.ToString().Trim() + "' WHERE [User]='" + Session["UserId"].ToString() + "'");
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "Alert", "<script language=\"javascript\" type=\"text/javascript\" > alert(\"Error: " + ex.Message + "\");</script>", false);
        }
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            objSQL.sqlExecuteNonQuery("UPDATE [QTP_INPUT] SET Email='"+ txtEmail.Text.Trim().ToString() +"' WHERE [User]='" + Session["UserId"].ToString() + "'");
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "Alert", "<script language=\"javascript\" type=\"text/javascript\" > alert(\"Error: " + ex.Message + "\");</script>", false);
        }
    }
}
